<?php

namespace app\store\model\staff;

use think\Model;


class Staff extends Model
{

    

    

    // 表名
    protected $name = 'staff';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'employmenttime_text',
        'confirmationtime_text',
        'sex_text',
        'maritalstatus_text',
    ];


    public function getTagList(){
        return ['1' => __('Q1'), '2' => __('Q2'), '3' => __('Q3'), '4' => __('Q4')];
    }


    public function getMaritalstatusList()
    {
        return ['0' => __('Maritalstatus 0'), '1' => __('Maritalstatus 1')];
    }
    public function getPoliticaloutlookList(){
        return ['0' => __('Politicaloutlook 0'), '1' => __('Politicaloutlook 1'), '2' => __('Politicaloutlook 2')];
    }
    public function getEducationList(){
        return ['0' => __('Education 0'), '1' => __('Education 1'), '2' => __('Education 2'), '3' => __('Education 3'), '4' => __('Education 4')];
    }
    public function getPoliticaloutlookTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['politicaloutlook']) ? $data['politicaloutlook'] : '');
        $list = $this->getPoliticaloutlookList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getMaritalstatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['maritalstatus']) ? $data['maritalstatus'] : '');
        $list = $this->getMaritalstatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getSexList()
    {
        return [ '1' => __('Sex 1'), '2' => __('Sex 2')];
    }

    public function getTypeList()
    {
        return [ '0' => '正式工', '1' => __('退休返聘'), '2' => __('实习生'), '3' => __('派遣工')];
    }

    public function getSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function getEmploymenttimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['employmenttime']) ? $data['employmenttime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getConfirmationtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['confirmationtime']) ? $data['confirmationtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setEmploymenttimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setConfirmationtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function rank()
    {
        return $this->belongsTo('app\store\model\staff\Rank', 'rank', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function jobgrade()
    {
        return $this->belongsTo('app\store\model\staff\Job', 'jobgrade', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function department(){
        return $this->belongsTo('app\store\model\wanlshop\Shop', 'shop_id', 'id', [], 'LEFT')->setEagerlyType(1);
    }

}
